package com.example.nacosdoscoveryribbon;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;

@Controller
@RequestMapping("nacosdiscoveryribbon")  //要不要斜杠都没关系
public class ConsumerController {
    @Autowired
    private RestTemplate restTemplate;

    @GetMapping("/test")
    @ResponseBody
    public String test() {
        ResponseEntity<String> entity = restTemplate
                .getForEntity("http://127.0.0.1:8081/api/test", String.class);
        return entity.getBody();
    }

    @GetMapping("/test2")
    @ResponseBody
    public String test2() {
        ResponseEntity<String> entity = restTemplate
                .getForEntity("http://nacosdiscoveryribbon/api/test", String.class);
        return entity.getBody();
    }

    @GetMapping("/test3")
    @ResponseBody
    public String test3() {
        ResponseEntity<String> entity = restTemplate
                .getForEntity("http://192.168.10.1:8081/api/test", String.class);
        return entity.getBody();
    }
}
